#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

struct student_info{
    int id;
    int score;
};

bool cmp(student_info a, student_info b);

int main(int argc, char const *argv[]){
    int n;
    while(cin >> n){
        student_info data[n];
        for (int i = 0; i < n; i++)
            cin >> data[i].id >> data[i].score;
        sort(data, data+n, cmp);
        for (int i = 0; i < n; i++)
            cout << data[i].id << ' '  << data[i].score << endl;
    }
    return 0;
}

bool cmp(student_info a, student_info b){
    if(a.score != b.score)
        return a.score < b.score;
    if(a.id != b.id)
        return a.id < b.id;
    //return false; //in case of complie fail
}